package com.ruoyi.project.experimentcheck.controller;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.experimentcheck.domain.ExperimentCheck;
import com.ruoyi.project.experimentcheck.service.ExperimentCheckService;
import com.ruoyi.project.system.user.domain.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;

@Controller
@RequestMapping("experimentcheck")
public class ExperimentCheckController extends BaseController {

    @Autowired
    private ExperimentCheckService experimentCheckService;

    private String prefix = "experimentcheck";

    @RequiresPermissions("experimentcheck:view")
    @GetMapping()
    public String check()
    {
        return prefix + "/experimentcheck";
    }

    @RequiresPermissions("experimentcheck:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExperimentCheck experimentCheck)
    {
        startPage();

        /**
         * 获取当前登录用户
         */
        User user=getSysUser();
        //获取当前用户名下的实验()
        experimentCheck.setCreateId(user.getUserId());

        List<ExperimentCheck> list = experimentCheckService.selectExperimentCheckList(experimentCheck);
        return getDataTable(list);
    }


   /* @GetMapping("/download")
    public void resourceDownload(String path, HttpServletRequest request, HttpServletResponse response)
            throws Exception
    {
        //下载路径
        //System.err.println(path);
        File file = new File(path);
        //获取最后一个“/”的下标索引
        int count=path.lastIndexOf("/");
        // 下载名称
        String downloadName = path.substring(count+1);
        //System.err.println(downloadName);
        response.setCharacterEncoding("utf-8");
        response.setContentType("multipart/form-data");
        response.setHeader("Content-Disposition",
                "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName));

        *//**
         * 数据库存储  路径 与实际电脑查看不同
         *//*
        String realPath=path.replace("/","\\");
        FileUtils.writeBytes(realPath, response.getOutputStream());
    }*/
}
